import request from "@/utils/request";
import type {SkuInfoData,SkuData,HasSpuResponseData,AllTradeMark,SpuHasImg,SaleAttrResponseData,HasSaleAttrResponseData,SpuData} from './type'

enum API {
  HASSPU_URL = '/admin/product/',
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  IMAGE_URL = '/admin/product/spuImageList/',
  SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  SKUINFO_URL = '/admin/product/findSpuInfoBySpuIdList/',
  REMOVESPU_URL = '/admin/product/deleteSpu/'
}
// 获取SPU列表数据
export const reqHasSpu = (page:number,limit:number,category3Id:number|string) => request.get<any,HasSpuResponseData>(API.HASSPU_URL+`${page}/${limit}?category3Id=${category3Id}`)
// 获取SPU品牌下拉数据
export const reqAllTradeMark = () => request.get<any,AllTradeMark>(API.ALLTRADEMARK_URL)
// 根据id获取SPU下的商品图片数据
export const reqSpuImageList = (spuId:number) => request.get<any,SpuHasImg>(API.IMAGE_URL+spuId)
// 根据id获取SPU销售属性列表数据
export const reqSpuHasSaleAttr = (spuId:number) => request.get<any,SaleAttrResponseData>(API.SPUHASSALEATTR_URL+spuId)
// 获取整个项目全部的销售属性[颜色、版本、尺码]（SPU销售属性下拉数据）
export const reqAllSaleAttr = () => request.get<any,HasSaleAttrResponseData>(API.ALLSALEATTR_URL)
// 新增SPU | 修改SPU
// data:要新增的SPU对象 | 要修改的SPU对象
export const reqAddOrUpdateSpu = (data:SpuData) => {
  if(data.id){
    return request.post<any,any>(API.UPDATESPU_URL,data)
  }else{
    return request.post<any,any>(API.ADDSPU_URL,data)
  }
}
// 删除SPU
export const reqRemoveSpu = (spuId:number|string)=>request.delete<any,any>(API.REMOVESPU_URL+spuId)
// 添加SKU
export const reqAddSku = (data:SkuData)=>request.post<any,any>(API.ADDSKU_URL,data)
// 查看sku列表
export const reqSkuList = (spuId:number|string)=>request.get<any,SkuInfoData>(API.SKUINFO_URL+spuId)